/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

/**
 *
 * @author The_Punisher_Khan
 */
import dao.AdministratorJpaController;
import entities.Administrator;

public class AdministratorService {
    private static AdministratorJpaController ac;

    private AdministratorJpaController getJPAController()
    {
        if(ac == null)
            ac = new AdministratorJpaController();
        return ac;
    }

    public boolean saveAdministrator(String handle,String firstName,String lastName,String password,String email)
    {
        boolean ret = true;
        ac = getJPAController();
        try
        {
            ac.create(new Administrator((Integer)0,handle,firstName,lastName,password,email));
        }
        catch (Exception e)
        {
            ret = false;
        }
        return ret;
    }

    public Administrator getAdministrator(String handle)
    {
        ac = getJPAController();
        return ac.getAdministratorByName(handle);
    }

    public boolean editAdministrator(Administrator a)
    {
        ac = getJPAController();
        try
        {
            ac.edit(a);
            return true;
        } catch (Exception e)
        {
            return false;
        }
    }

    public boolean deleteAdministrator(Administrator a)
    {
        ac = getJPAController();
        try
        {
            ac.destroy(a.getIdAdministrator());
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
}